package utils
{
	import flash.display.Sprite;
	
	public class Parallax extends Sprite
	{
		private var offsets:Array;
		private var _scop:Number=5;
		private var _x:Number=0;
		private var _y:Number=0;
		public function Parallax(parallax:Array,scop:Number=10)
		{
			offsets=parallax;
			_scop = scop;
		}
	   
		override public function set x(value:Number):void{
			if(Math.abs(value)>=_scop) return ;
			for (var j:int = 0; j < this.numChildren; j++) 
			{
				this.getChildAt(j).x=value*offsets[j];;
			}
			_x=value;
		}
		override public function get x():Number{
		   return _x;
		}
		override public function get y():Number{
		   return _y;
		}
		public function setPostion(px:Number,py:Number):void{
			var tx:Boolean = Math.abs(px)<_scop;
			var ty:Boolean = Math.abs(py)<_scop;
			for (var j:int = 0; j < this.numChildren; j++) 
			{
				if(tx){
					this.getChildAt(j).x=px*offsets[j]-40;
				}
				if(ty){
					this.getChildAt(j).y=py*offsets[j]-40;
				}	
			}
			if(tx){
				_x=px;
			}
			if(ty){
				_y=py;
			}
		}
		override public function set y(value:Number):void{
			if(Math.abs(value)>=_scop) return ;
			for (var j:int = 0; j < this.numChildren; j++) 
			{
				this.getChildAt(j).y=value*offsets[j];;
			}
			_y=value;
		}
	}
}